home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / SCSI / SCSI Async Sample / Src / SpinCursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.1 KB  |  96 lines  |  [TEXT/KAHL]

  1. /*                                    SpinCursor.c                                */
  2. /*
  3.  * SpinCursor.c
  4.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  5.  * This is based on a sample in Think Reference 2.0.
  6.  */
  7. #ifndef THINK_C                /* MPW includes            */
  8. #include <Errors.h>
  9. #include <Script.h>
  10. #include <Types.h>
  11. #include <Files.h>
  12. #include <Resources.h>
  13. #include <QuickDraw.h>
  14. #include <Fonts.h>
  15. #include <Events.h>
  16. #include <Windows.h>
  17. #include <ToolUtils.h>
  18. #include <Memory.h>
  19. #include <Menus.h>
  20. #include <Lists.h>
  21. #include <Printing.h>
  22. #include <Dialogs.h>
  23. #include <StandardFile.h>
  24. #endif
  25. #define kAnimationInterval        (6)            /* Ticks                */
  26. /*
  27.  * This is used by the animated cursor subroutine.
  28.  */
  29. typedef struct {
  30.     unsigned short        nFrames;
  31.     unsigned short        nextFrame;
  32.     CursHandle            frame[1];
  33. } ACUR_Record, *ACUR_Ptr, **ACUR_Handle;
  34. ACUR_Handle                gACUR_Handle;
  35. #define ACUR            (**gACUR_Handle)
  36. unsigned long            gACUR_NextAnimation;
  37.  
  38. void                    SetupAnimatedCursor(
  39.         short                        acurResID
  40.     );
  41. void                    SpinCursor(void);
  42.  
  43.  
  44. /*
  45.  * SetupAnimatedCursor
  46.  * Build the animated cursor handle array (in global gACUR_Handle)
  47.  */
  48. void
  49. SetupAnimatedCursor(
  50.         short                        acurResID
  51.     )
  52. {
  53.         short                    cursorID;
  54.         short                    i;
  55.  
  56.         gACUR_Handle = (ACUR_Handle) GetResource('acur', acurResID);
  57.         if (gACUR_Handle != NULL) {
  58.             DetachResource((Handle) gACUR_Handle);
  59.             for (i = 0; i < ACUR.nFrames; i++) {
  60.                 cursorID = ((unsigned long) ACUR.frame[i]) >> 16;
  61.                 ACUR.frame[i] = GetCursor(cursorID);
  62.                 if (ACUR.frame[i] == NULL)
  63.                     break;
  64.                 HNoPurge((Handle) ACUR.frame[i]);
  65.             }
  66.             ACUR.nFrames = i;
  67.             ACUR.nextFrame = 0;
  68.             if (i == 0) {
  69.                 DisposeHandle((Handle) gACUR_Handle);
  70.                 gACUR_Handle = NULL;
  71.             }
  72.         }
  73.         gACUR_NextAnimation = 0;
  74. }
  75.  
  76. /*
  77.  * SpinCursor
  78.  * This is called repeatedly to change the cursor animation.
  79.  */
  80. void
  81. SpinCursor(void)
  82. {
  83.         unsigned long                now;
  84.         
  85.         if (gACUR_Handle != NULL) {
  86.             now = TickCount();
  87.             if (now > gACUR_NextAnimation) {
  88.                 gACUR_NextAnimation = now + kAnimationInterval;
  89.                 if (ACUR.nextFrame >= ACUR.nFrames)
  90.                     ACUR.nextFrame = 0;
  91.                 SetCursor(*ACUR.frame[ACUR.nextFrame]);
  92.                 ++ACUR.nextFrame;
  93.             }
  94.         }
  95. }
  96.